package com.itdct.onflow.core.extend

import java.text.SimpleDateFormat
import java.util.*

/**
 * @author DCTANT
 * @date 2021/4/14 10:27:15
 * @description
 */
const val yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"
const val yyyyMMddHHmmssT = "yyyy-MM-dd HH:mm:ss T"
const val yyyyMMdd = "yyyy-MM-dd"

fun getTimeStamp(): Long {
    return System.currentTimeMillis()
}

fun String.formatTimeToTimeStamp(timeFormat: String = yyyyMMddHHmmss): Long {
    val simpleDateFormat = SimpleDateFormat(timeFormat)
    val date = simpleDateFormat.parse(this)
    return date.time
}

fun Long.timeStampToFormatDate(timeFormat: String = yyyyMMddHHmmss): String {
    val simpleDateFormat = SimpleDateFormat(timeFormat)
    val format = simpleDateFormat.format(Date(this))
    return format
}

fun getTimeInFormat(timeFormat: String = yyyyMMddHHmmss): String {
    val timeStamp = getTimeStamp()
    val timeStampToFormatDate = timeStamp.timeStampToFormatDate(timeFormat)
    return timeStampToFormatDate
}